#include "stdafx.h"
#include "CppUnitTest.h"

#include "System/Base/Integer.h"
#include "System/Base/Scene.h"
#include "System/Base/IteratorBuilder.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Native::System;

namespace TestNativeSystem
{
    TEST_CLASS(ArrayIterator_Tester)
    {
        TEST_METHOD(ArrayIterator_ConstructedByEmptyArray)
        {
            CArray<Int32s> array;
            CArrayIterator<Int32s> iterator(&array);

            Assert::IsTrue(iterator.Done());
            Assert::IsTrue(iterator.First() == nullptr);
            Assert::IsTrue(iterator.Next() == nullptr);
        }

        TEST_METHOD(ArrayIterator_ConstructedByFilledArray)
        {
            CArray<Int32s> array;

            array.Append(Int32s(1));
            array.Append(Int32s(2));

            CArrayIterator<Int32s> iterator(&array);

            Assert::IsTrue(iterator.Done());
            Assert::IsTrue(iterator.Next() == nullptr);
            Assert::IsFalse(iterator.First() == nullptr);
        }

        TEST_METHOD(ArrayIterator_Forward)
        {
            CArray<Int32s> array;
            int32_t counter = 0;

            array.Append(Int32s(0));
            array.Append(Int32s(1));
            array.Append(Int32s(2));
            array.Append(Int32s(3));
            array.Append(Int32s(4));
            array.Append(Int32s(5));
            array.Append(Int32s(6));

            auto iterator = UArrayIteratorBuilder<Int32s>::CreateForward(&array);

            NATIVE_FOREACH(&iterator, each) {
                Assert::IsTrue((*each).Value() == counter);

                counter++;
            }
        }

        TEST_METHOD(ArrayIterator_Back)
        {
            CArray<Int32s> array;
            int32_t counter = 6;

            array.Append(Int32s(0));
            array.Append(Int32s(1));
            array.Append(Int32s(2));
            array.Append(Int32s(3));
            array.Append(Int32s(4));
            array.Append(Int32s(5));
            array.Append(Int32s(6));

            auto iterator = UArrayIteratorBuilder<Int32s>::CreateBackward(&array);

            NATIVE_FOREACH(&iterator, each) {
                Assert::IsTrue((*each).Value() == counter);
                counter--;
            }
        }
    };
}